package org.bite.lesson02;

public class Demo_204 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
            while(true){
                System.out.println(Thread.currentThread() + "hello");
                try{
                    Thread.sleep(1000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
            }
        });
        //thread.start();
        System.out.println("线程是否存活：" + thread.isAlive());
        System.out.println("线程是否为后台线程 "+ thread.isDaemon());
        //将线程设置为后台线程
        thread.setDaemon(true);
        thread.start();
        System.out.println("线程是否存活：" + thread.isAlive());
        System.out.println("线程是否为后台线程 "+ thread.isDaemon());

        int i = 0;
        while(i < 2){
            i++;
            Thread.sleep(1000);
            System.out.println("main()主线程没有结束……");
        }
        Thread.sleep(1000);
        System.out.println("结束main()主线程");
    }
}
